﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CSharp.Libs.Net;
using CSharp.Libs.Koc;

namespace CSharp.Libs.Koc.KernelModels
{
    public class UserValidator
    {
        #region declarations
        private Kernel _AB = null;
        #endregion



        #region constructor / terminator
        public UserValidator(
            Kernel AB)
        {
            _AB = AB;
        }

        ~UserValidator()
        {
            if (_AB != null)
            {
                _AB = null;
            }
        }
        #endregion



        #region private functions
        private Boolean _UserIsValid(
            String fbuid)
        {
            try
            {
                PostSubmitter PS = new PostSubmitter(constants.CHECK_USER_URL);
                
                PS.PostItems.Add("action", "exists");
                PS.PostItems.Add("FbUid", fbuid);
                
                String strResult = PS.Post();

                if (strResult.StartsWith("true"))
                {
                    return true;
                }
            }
            catch (Exception ex)
            {
                _AB.EC.AddException(ex, this.ToString(), _AB.EC.Tools.GetCurrentMethodName());
            }

            return false;
        } 
        #endregion



        #region interface
        #region properties
        #endregion

        #region methods
        public Boolean UserIsValid(
            String fbuid)
        {
            return _UserIsValid(fbuid);
        }
        #endregion
        #endregion
    }
}
